import redis

client = redis.Redis()
# 添加数据
datas = ['你好', 1, 5, 'src']
client.sadd('ssetpython', '你好')
client.sadd('ssetpython', 1)
client.sadd('ssetpython', *datas)
# # 读取数据
# print(client.scard('ssetpython')) # 4
# print(client.spop('ssetpython')) # b'5'
# print(client.scard('ssetpython')) # 3
# 使用循环从redis集合中获取数据
# print(client.scard('ssetpython'))  # 4
# for _ in range(3):
#     data = client.spop('ssetpython')
#     '''
#     b'\xe4\xbd\xa0\xe5\xa5\xbd'
#     b'5'
#     b'src'
#     '''
#     print(data)
# print(client.scard('ssetpython'))  # 1
# 获取集合的所有元素
# print(client.smembers('ssetpython'))  # b'5', b'src', b'\xe4\xbd\xa0\xe5\xa5\xbd'
# 删除元素
# print(client.smembers('ssetpython'))  # b'5', b'src', b'\xe4\xbd\xa0\xe5\xa5\xbd'
# print(client.srem('ssetpython', 5))  # 1
# print(client.smembers('ssetpython'))  # {b'\xe4\xbd\xa0\xe5\xa5\xbd', b'src', b'1'}

print(client.sadd('spython1', 1, 2, 3, 4, 5))
print(client.sadd('spython2', 4, 5, 6, 7))
print(client.sinter('spython1', 'spython2'))  # {b'5', b'7', b'4', b'6'}
print(client.sunion('spython1', 'spython2'))  # {b'4', b'2', b'3', b'1', b'7', b'5', b'6'}
print(client.sdiff('spython1', 'spython2'))  # {b'3', b'1', b'2'}
